package com.chenwenxuan.sync.utils.parser;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import ognl.OgnlException;

import com.chenwenxuan.sync.console.model.TaskArg;
import com.chenwenxuan.sync.console.model.TaskArgs;

public class TaskArgsParser {
	
	private TaskArgs taskArgs;
	private Map <String, String> paramMap;
	private Date now;
	
	public TaskArgsParser(TaskArgs taskArgs, Date now) {
		this.taskArgs = taskArgs;
		this.now = now;
	}
	
	public void parse() throws OgnlException {
		List <TaskArg>  args = taskArgs.getTaskArg();
		Map <String, String> paramMap = new TreeMap<String, String>();
		DatePlaceHolderParser placeHolderParser = new DatePlaceHolderParser(now);
		for (TaskArg arg : args) {
			String value = placeHolderParser.parse(arg.getArgValue());
			paramMap.put(arg.getArgName(), value);
		}
	}
	
	public Map <String, String> getParamMap() {
		return paramMap;
	}

}
